//
//  CellOfDetailsPageUserSearchResult.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/2.
//  Copyright © 2016年 KX. All rights reserved.
#import "UIImageView+WebCache.h"
#import "Masonry.h"
#import "CellOfDetailsPageUserSearchResult.h"
@interface CellOfDetailsPageUserSearchResult ()
@property (nonatomic, strong) UILabel *labelOfUserName;
@property (nonatomic, strong) UILabel *labelOftitle;
@property (nonatomic, strong) UILabel *labelOfCountries ;
@property (nonatomic, strong) UILabel *labelOfCities ;

@property (nonatomic, strong) UIImageView *imageViewOfAvatar;
@property (nonatomic, strong) UIView *grayView;
@end
@implementation CellOfDetailsPageUserSearchResult
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.labelOftitle = [[UILabel alloc]init];
        self.labelOfCities = [[UILabel alloc]init];
        self.labelOfUserName = [[UILabel alloc]init];
        self.labelOfCountries = [[UILabel alloc]init];
        self.imageViewOfAvatar = [[UIImageView alloc]init];
        self.grayView = [[UIView alloc]init];
        [self.contentView addSubview:self.grayView];
        [self.contentView addSubview:self.labelOfCountries];
        [self.contentView addSubview:self.labelOfCities];
        [self.contentView addSubview:self.labelOftitle];
        [self.contentView addSubview:self.labelOfUserName];
        [self.contentView addSubview:self.imageViewOfAvatar];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self.imageViewOfAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).mas_offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-10);
        make.left.equalTo(self.contentView.mas_left).mas_offset(10);
        make.height.width.mas_equalTo(80);
    }];
    self.imageViewOfAvatar.backgroundColor = [UIColor redColor];
    self.imageViewOfAvatar.layer.cornerRadius = 40;
    self.imageViewOfAvatar.layer.masksToBounds = YES;
    [self.grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.height.mas_offset(1);
        make.left.equalTo(self.contentView.mas_left).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
    }];
    self.grayView.backgroundColor = [UIColor grayColor];
    [self.labelOfUserName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageViewOfAvatar.mas_right).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        make.top.equalTo(self.contentView.mas_top).mas_offset(20);
        make.height.mas_offset(15);
    }];
    [self.labelOftitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-20);
        make.height.mas_offset(10);
        make.left.equalTo(self.imageViewOfAvatar.mas_right).mas_offset(10);
        make.width.mas_offset(50);
    }];
    self.labelOftitle.textColor = [UIColor grayColor];
    self.labelOftitle.font = [UIFont systemFontOfSize:12];
    [self.labelOfCountries mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-20);
        make.height.mas_offset(10);
        make.width.mas_offset(80);
        make.left.equalTo(self.labelOftitle.mas_right);
    }];
    self.labelOfCountries.textColor = [UIColor grayColor];
    self.labelOfCountries.font = [UIFont systemFontOfSize:12];
    [self.labelOfCities mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-20);
        make.height.mas_offset(10);
        make.width.mas_offset(50);
        make.left.equalTo(self.labelOfCountries.mas_right).mas_offset(5);
    }];
    self.labelOfCities.textColor = [UIColor grayColor];
    self.labelOfCities.font = [UIFont systemFontOfSize:12];
    
    
}
- (void)setModel:(ModelOfUserSpecificSearchResult *)model{
    _model = model;
    [self.imageViewOfAvatar sd_setImageWithURL:[NSURL URLWithString:model.avatar]];
    self.labelOfUserName.text = model.username;
    self.labelOftitle.text = model.title;
    self.labelOfCountries.text = [NSString stringWithFormat:@"|去过%ld个国家,",model.countries];
    self.labelOfCities.text = [NSString stringWithFormat:@"%ld个城市",model.cities];
    }
@end
